package model.events;

import model.entity.Entity;
import model.entity.container.ProductContainer;

/**
 * An event that is fired when an entity is added, moved, or removed from the database.
 * 
 * @author Ryan Cheatham
 * 
 * @param <T>
 *          The type of entity that was moved.
 */
public class EntityEvent extends GenericEntityEvent
{
  /**
   * The <code>entity moved</code> event. This event occurs when the entity is moved from one
   * <code>ProductContainer</code> to another.
   */
  public static final int        ENTITY_MOVED   = 0;

  /**
   * The <code>entity added</code> event. This event occurs when the entity is added to a
   * <code>ProductContainer</code>.
   */
  public static final int        ENTITY_ADDED   = 1;

  /**
   * The <code>entity removed</code> event. This event occurs when the entity is removed from a
   * <code>ProductContainer</code>.
   */
  public static final int        ENTITY_REMOVED = 2;

  private final int              id;
  private final Entity           entity;

  private final ProductContainer oldContainer;
  private final ProductContainer newContainer;

  // @formatter:off
  /**
   * Constructs a new <code>EntityEvent</code> with the given entity, ID, old container, and new
   * container.
   * 
   * @param entity
   *          The entity which is associated with this event.
   * @param id
   *          The type of event that has occurred.
   * @param oldContainer
   *          The container that the entity was in previous to this event.
   * @param newContainer
   *          The container that the entity will be in after this event.
   * 
   *          {@pre entity != null} {@pre 0 <= id <= 2}
   */
  // @formatter:on
  public EntityEvent(Entity entity, int id, ProductContainer oldContainer,
      ProductContainer newContainer)
  {
    this.entity = entity;
    this.id = id;
    this.oldContainer = oldContainer;
    this.newContainer = newContainer;
  }

  /**
   * Returns the event ID of this event.
   * 
   * {@post 0 <= retval <= 2}
   */
  public int getID()
  {
    return id;
  }

  /**
   * Returns the item of the event.
   * 
   * {@post retval != null}
   */
  public Entity getEntity()
  {
    return entity;
  }

  /**
   * Gets the {@link ProductContainer} that the item used to be in before this event. Can be
   * <code>null</code>.
   */
  public ProductContainer getOldContainer()
  {
    return oldContainer;
  }

  /**
   * Gets the {@link ProductContainer} that the item will be in after this event. Can be
   * <code>null</code>.
   */
  public ProductContainer getNewContainer()
  {
    return newContainer;
  }
}
